home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / wsanet8a / wsanet / src / wsanet.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-22  |  6.9 KB  |  283 lines

  1. /* WSANet.C - Initialization for WSANET.VBX */
  2.  
  3. #define WSANet_C
  4.  
  5. #include "WSANet.H"
  6. #include "Version.H"
  7. #include "NetClnt.H"    // NetClient control Model
  8. #include "NetSrvr.H"    // NetServer control Model
  9. #include "Ini.H"        // Ini control Model
  10.  
  11. static const char szEmbedded[] = "WSANET.VBX (c)1993 Ian C. Blenke";
  12.  
  13. // Specific globals to INIT.C
  14. static WORD wVbxUsers      = 0;
  15. static BOOL bDevTimeInited = FALSE;
  16.  
  17. /* BOOL bHelpStdPropEvt(WPARAM, LPMODEL);
  18.     Purpose: To return TRUE if the property is standard, and
  19.              FALSE if it is custom
  20. */
  21. BOOL bHelpStdPropEvt(WPARAM wParam, LPMODEL lpModel)
  22. {
  23.  switch(LOBYTE(wParam))
  24.  {
  25.   case VBHELP_PROP:
  26.     if(lpModel->npproplist[HIBYTE(wParam)] >= PPROPINFO_STD_LAST)
  27.         return(TRUE);
  28.   break;
  29.  
  30.   case VBHELP_EVT:
  31.     if(lpModel->npeventlist[HIBYTE(wParam)] >= PEVENTINFO_STD_LAST)
  32.         return(TRUE);
  33.   break;
  34.  }
  35.  return(FALSE);
  36. } /* bHelpStdPropEvt() */
  37.  
  38.  
  39. /* BOOL DisplayHelpTopic(WORD, WPARAM, LPMODEL);
  40.     Purpose: To display context sensitive help
  41. */
  42. BOOL DisplayHelpTopic(WORD wControl, WPARAM wParam, LPMODEL lpModel)
  43. {
  44.  WORD *wHelpProperties = NULL;
  45.  WORD *wHelpEvents = NULL;
  46.  
  47. #ifdef USE_VCPP
  48.  lpModel = lpModel;
  49. #endif /* USE_VCPP */
  50.  
  51.  switch(wControl)
  52.  {
  53.   case TOPIC_CONTROL_NETCLIENT:
  54.     wHelpProperties = wNetClientHelpProps;
  55.     wHelpEvents = wNetClientHelpEvents;
  56.   break;
  57.  
  58.   case TOPIC_CONTROL_INI:
  59.     wHelpProperties = wIniHelpProps;
  60.     wHelpEvents = NULL;
  61.   break;
  62.  
  63.   case TOPIC_CONTROL_NETSERVER:
  64.     wHelpProperties = wNetServerHelpProps;
  65.     wHelpEvents = wNetServerHelpEvents;
  66.   break;
  67.  
  68.   default:
  69.     return(ERR_None);
  70.  }
  71.  
  72.  switch(LOBYTE(wParam))
  73.  {
  74.   case VBHELP_PROP:
  75.      if(wHelpProperties)
  76.      {
  77.       if(WinHelp(NULL, WSANET_HELPFILE, HELP_CONTEXT, (DWORD)(wHelpProperties[HIBYTE(wParam)])))
  78.          return(ERR_None);
  79.      }
  80.   break;
  81.  
  82.   case VBHELP_EVT:
  83.      if(wHelpEvents)
  84.      {
  85.       if(WinHelp(NULL, WSANET_HELPFILE, HELP_CONTEXT, (DWORD)(wHelpEvents[HIBYTE(wParam)])))
  86.          return(ERR_None);
  87.      }
  88.   break;
  89.  
  90.   case VBHELP_CTL:
  91.      if(WinHelp(NULL, WSANET_HELPFILE, HELP_CONTEXT, (DWORD)wControl))
  92.         return(ERR_None);
  93.  }
  94.  return(ERR_None);
  95. } // DisplayHelpTopic()
  96.  
  97.  
  98.     // List of all the controls this VBX supports
  99. LPMODEL modellistControls[] =
  100. {
  101.  NULL,                              // This is changed in code
  102.  MODELLIST_INI,
  103.  MODELLIST_NETSERVER,
  104.  NULL
  105. };
  106.  
  107.     // Model information structure
  108. MODELINFO modelinfoControls =
  109. {
  110.  VB100_VERSION,                     // This is changed in code
  111.  (LPMODEL FAR *)&modellistControls
  112. };
  113.  
  114.  
  115. /* int CALLBACK LibMain(HANDLE, WORD, WORD, LPSTR);
  116.     Purpose: Handles the startup of the VBX (DLL)
  117.     Note:    Quite unstable in here.
  118. */
  119. int CALLBACK LibMain(HANDLE hModule, WORD wDataSeg, WORD cbHeapSize,
  120.                      LPSTR lpszCmdLine)
  121. {
  122.  #ifdef USE_VCPP
  123.   lpszCmdLine=lplszCmdLine;
  124.   cbHeapSize=cbHeapSize;
  125.   wDataSeg=wDataSeg;
  126.  #endif /* USE_VCPP */
  127.  
  128.  // Remember the Module (Instance) of the VBX
  129.  hModDLL  = hModule;
  130.  
  131.  return(1);
  132. } /* LibMain() */
  133.  
  134.  
  135. /* BOOL CALLBACK _export VBINITCC(USHORT, BOOL);
  136.     Purpose: To handle the Visual Basic entrance point for the VBX
  137. */
  138. BOOL CALLBACK _export VBINITCC(USHORT usVersion, BOOL bRuntime)
  139. {
  140.     // Keep count of the number of users
  141.  ++wVbxUsers;
  142.  
  143. #ifdef DESIGN_TIME
  144.     // Register popup class if this is from the development environment.
  145.  if (!bRuntime && !bDevTimeInited)
  146.  {
  147.   WNDCLASS class;
  148.  
  149.     // Show the beginning debug banner
  150. #ifdef DEBUG_BUILD
  151.   OutputDebugString((LPSTR)WSANET_BANNER);
  152. #endif /* DEBUG_BUILD */
  153.  
  154.   class.style         = 0; // (Invisible)
  155.   class.lpfnWndProc   = (WNDPROC)AboutWndProc;
  156.   class.cbClsExtra    = 0;
  157.   class.cbWndExtra    = 0;
  158.   class.hInstance     = hModDLL;
  159.   class.hIcon         = NULL;
  160.   class.hCursor       = NULL;
  161.   class.hbrBackground = NULL;
  162.   class.lpszMenuName  = NULL;
  163.   class.lpszClassName = CLASS_ABOUTPOPUP;
  164.  
  165.   if (!RegisterClass(&class))
  166.       return FALSE;
  167.  
  168.     // We successfully initialized the stuff we need at dev time
  169.   bDevTimeInited = TRUE;
  170.  }
  171. #else
  172.  if(!bRunTime) return(FALSE);
  173. #endif //DESIGN_TIME
  174.  
  175.  
  176.     // Hack to allow context sensitive help in VB2.0 and newer
  177.     // in the single model NetServer and INI controls.
  178.  if(usVersion>=VB200_VERSION)
  179.  {
  180.   modelNetServer.usVersion = VB200_VERSION;
  181.   modelIni.usVersion = VB200_VERSION;
  182.  }
  183.  else
  184.  {
  185.   modelNetServer.usVersion = VB100_VERSION;
  186.   modelIni.usVersion = VB100_VERSION;
  187.  }
  188.  
  189.     // Initialize the network
  190.  if(!netStartup())
  191.  {
  192.   char szTemp[256];
  193.  
  194.   if(LoadString(hModDLL, IDS_WRONGVER, (LPSTR)szTemp, sizeof(szTemp)))
  195.   {
  196.    MessageBox(NULL, (LPSTR)szTemp,
  197.              (LPSTR)STRING_WRONGTITL, MB_ICONSTOP | MB_OK);
  198.   }
  199.   return(FALSE);
  200.  }
  201.  
  202.  if(!VBRegisterModel(hModDLL, &modelIni))
  203.  {
  204.   OutputDebugString("Failure registering Ini control!\n");
  205.   return(FALSE);
  206.  }
  207.  
  208.  if(!VBRegisterModel(hModDLL, &modelNetServer))
  209.  {
  210.   OutputDebugString("Failure registering NetServer control!\n");
  211.   return(FALSE);
  212.  }
  213.  
  214. #ifdef VB100_CDK
  215.  if(usVersion==VB100_VERSION) return(VBRegisterModel(hModDLL, &modelNetClient_VB1));
  216. #ifdef VB200_CDK
  217.  if(usVersion==VB200_VERSION) return(VBRegisterModel(hModDLL, &modelNetClient_VB2));
  218. #ifdef VB300_CDK
  219.  if(usVersion>=VB300_VERSION) return(VBRegisterModel(hModDLL, &modelNetClient_VB3));
  220. #endif /* VB300_CDK */
  221. #endif /* VB200_CDK */
  222. #endif /* VB100_CDK */
  223. } /* VBINITCC() */
  224.  
  225.  
  226. /* LPMODELINFO CALLBACK VBGetModelInfo(USHORT usVersion);
  227.     Purpose: To export the model information without actually
  228.              registering it (Read VB3.0 Professional book
  229.              #1, page 274)
  230. */
  231. LPMODELINFO FAR PASCAL _export VBGetModelInfo(USHORT usVersion)
  232. {
  233. #ifdef VB100_CDK
  234.  if(usVersion==VB100_VERSION)
  235.  {
  236.   modellistControls[0] = (LPMODEL)&modelNetClient_VB1;
  237.   modelinfoControls.usVersion = usVersion;
  238.   return(&modelinfoControls);
  239.  }
  240. #ifdef VB200_CDK
  241.  if(usVersion==VB200_VERSION)
  242.  {
  243.   modellistControls[0] = (LPMODEL)&modelNetClient_VB2;
  244.   modelinfoControls.usVersion = usVersion;
  245.   return(&modelinfoControls);
  246.  }
  247. #ifdef VB300_CDK
  248.  if(usVersion>=VB300_VERSION)
  249.  {
  250.   modellistControls[0] = (LPMODEL)&modelNetClient_VB3;
  251.   modelinfoControls.usVersion = VB300_VERSION;
  252.   return(&modelinfoControls);
  253.  }
  254. #endif /* VB300_CDK */
  255. #endif /* VB200_CDK */
  256. #endif /* VB100_CDK */
  257. }/* VBGetModelInfo() */
  258.  
  259.  
  260. /* VOID CALLBACK _export VBTERMCC(VOID);
  261.     Purpose: To handle the Visual Basic exit point from the VBX
  262. */
  263. VOID CALLBACK _export VBTERMCC(VOID)
  264. {
  265.  --wVbxUsers;
  266.  
  267. #ifdef DESIGN_TIME
  268.  if (!wVbxUsers & bDevTimeInited)
  269.  {
  270.   // Free any resources created for Dev environment
  271.   UnregisterClass(CLASS_ABOUTPOPUP, hModDLL);
  272. #ifdef VB200_CDK
  273.   WinHelp(NULL, WSANET_HELPFILE, HELP_QUIT, NULL);
  274. #endif /* VB200_CDK */
  275.  }
  276. #endif //DESIGN_TIME
  277.  
  278.  netCleanup();
  279.  return;
  280. } /* VBTERMCC() */
  281.  
  282. /* End of WSANet.C */
  283.